package com.tvserials.notification.parser;


import com.tvserials.notification.dto.Episode;
import com.tvserials.notification.dto.Serial;
import com.tvserials.notification.exceptions.NetworkConnectionException;
import com.tvserials.notification.exceptions.PageParseException;
import com.tvserials.notification.utils.VOUtils;
import com.tvserials.notification.vo.TvEpisodeFilterVO;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Created by Alex on 21.04.2014.
 */
public abstract class DefaultPageParser implements PageParser {
    @Override
    public List<Episode> parsePage(TvEpisodeFilterVO filterVO) throws NetworkConnectionException, PageParseException {
        List<Serial> allowedSerials = filterVO.getSerials();
        if (!VOUtils.isSignedOnSourceSystem(allowedSerials, getSourceType())) {
            return new ArrayList<Episode>();
        }

        return parse(filterVO);
    }

    protected abstract List<Episode> parse(TvEpisodeFilterVO filterVO) throws NetworkConnectionException, PageParseException;

    protected boolean graterThan(Date latestSyncDate, Date pubDate) {
        return (latestSyncDate == null || pubDate.after(latestSyncDate));
    }
}
